// const baseUrl = 'http://192.168.0.113:8090/';
const baseUrl = 'http://gmpapi.cddfct.com:8089/zhpt/';
const imgBaseUrl = 'http://gmpapi.cddfct.com:8089/zhpt/'

const fetch = (url,data={}) =>{
	return new Promise((resolve,reject) => {
		axios({
			method:'get',
			url:url,
			params:data,
			headers:{
				'X-Requested-With': 'XMLHttpRequest',
				'Content-Type': 'appliccation/x-www-form-urlencoded'
			},
		}).then(resp=>{
			resolve(resp)
		}).catch(err=>{
			reject(err);
		})  
	})
}

/* json-post */
const postJson = (url,data={}) =>{
	return new Promise((resolve,reject)=>{
		axios.post(url,data).then(resp => {
			resolve(resp)
		},reject)
	})
}

/* form-post */
const postForm = (url,data={}) =>{
	return new Promise((resolve,reject)=>{
		axios({
			method:'post',
			url:url,
			data:data,
		}).then(resp=>{
			resolve(resp)
		},reject)
	})
}

const fetchByAppCode = (url,data={}) =>{
	return new Promise((resolve,reject) => {
		axios({
			method:'get',
			url:url,
			params:data,
			headers:{
				'X-Requested-With': 'XMLHttpRequest',
				'Content-Type': 'appliccation/x-www-form-urlencoded',
				'Authorization': 'APPCODE 94017554e3d14822a034b79ac7d847c6'
			},
		}).then(resp=>{
			resolve(resp)
		}).catch(err=>{
			reject(err);
		})  
	})
}

//let baseUrl = 
let api = {
	baseUrl: imgBaseUrl,
    // getWeather: function() {
    //     return fetchByAppCode('http://ali-weather.showapi.com/hour24?area=%e9%9d%92%e7%be%8a')
	// },
	getMsg: function(body) {
		return fetch(baseUrl + 'new/getNews',body)
	},
	getWeather: function() {
		return fetch('https://www.tianqiapi.com/api?version=v1&city=成都')
	},
	getTickData: function() {
		return fetch('./static/data/tickData.json')
	},
	getNarratorData: function(body) {
		return fetch(baseUrl + 'statistics/commentator',body)
	},
	getParkData: function() {
		return fetch('./static/data/parkData.json')
	},
	getVolunteerData: function(body) {
		return fetch(baseUrl + 'statistics/volunteer',body)
	},
	getCityList: function() {
		return fetch('./static/data/cityList.json')
	},
	getMenuList: function() {
		return fetch(baseUrl + 'menu/getMenu')
	},
	addUser: function(body) {
		return postJson(baseUrl + 'user/adduser')
	},
	login: function(body) {
		return postJson(baseUrl + 'user/login',body)
	},
	upload: function(body) {
		return postForm(baseUrl + 'file/upload',body)
	},
	setPublish: function(body) {
		return postJson(baseUrl + 'screen/publish',body)
	},
	getPublish: function(body) {
		return fetch(baseUrl + 'screen/getScreen',body)
	},
	getGroupList: function() {
		return fetch(baseUrl + 'user/getAllUserGroup')
	},
	addUser: function(body) {
		return postJson(baseUrl + 'user/addUser',body)
	},
	getUserList: function(body) {
		return fetch(baseUrl + 'user/getAllUser',body)
	},
	editUser: function(body) {
		return postJson(baseUrl + 'user/updateUser',body)
	},
	delUser: function(body) {
		return postJson(baseUrl + 'user/deleteUser',body)
	},
	addUserGroup: function(body) {
		return postJson(baseUrl + 'user/addUserGroup',body)
	},
	edieUserGroup: function(body) {
		return postJson(baseUrl + 'user/updateUserGroup',body)
	},
	delGroup: function(body) {
		return postJson(baseUrl + 'user/deleteUserGroup',body)
	},
	addMenu: function(body) {
		return postJson(baseUrl + 'new/addModule',body)
	},
	添加讲解员: function(body) {
		return postJson(baseUrl + 'commentator/add',body)
	},
	查询所有讲解员: function(body) {
		return postJson(baseUrl + 'commentator/getAllCommentator',body)
	},
	更新讲解员: function(body) {
		return postJson(baseUrl + 'commentator/updateCommentator',body)
	},
	删除讲解员: function(body) {
		return fetch(baseUrl + 'commentator/deleteCommentator',body)
	},
	批量添加在岗人员: function(body) {
		return postJson(baseUrl + 'online/add-commentator',body)
	},
	批量添加讲解日志: function(body) {
		return postJson(baseUrl + 'log/addLog',body)
	},
	查询所有日志: function(body) {
		return fetch(baseUrl + 'log/getAllLog',body)
	},
	添加设备: function(body) {
		return postJson(baseUrl + 'device/addDevice',body)
	},
	获取设备记录: function(body) {
		return fetch(baseUrl + 'device/getDeviceByType',body)
	},
	讲解工作查询: function(body) {
		return fetch(baseUrl + 'record/list',body)
	},
	添加讲解工作: function(body) {
		return postJson(baseUrl + 'record/add',body)
	},
	更新讲解批次: function(body) {
		return postJson(baseUrl + 'record/update-batch',body)
	},
	更新讲解机数量: function(body) {
		return postJson(baseUrl + 'record/update-explain-count',body)
	},
	更新平板数量: function(body) {
		return postJson(baseUrl + 'record/update-ipad-count',body)
	},
	添加志愿者: function(body) {
		return postJson(baseUrl + 'volunteer/add',body)
	},
	查询志愿者: function(body) {
		return postJson(baseUrl + 'volunteer/list',body)
	},
	查询志愿者: function(body) {
		return fetch(baseUrl + 'volunteer/list',body)
	},
	修改志愿者: function(body) {
		return postJson(baseUrl + 'volunteer/update',body)
	},
	删除志愿者: function(body) {
		return postJson(baseUrl + 'volunteer/delete?id=' + body.id)
	},
	添加活动: function(body) {
		return postJson(baseUrl + 'activities/addActivities',body)
	},
	获取活动列表: function(body) {
		return fetch(baseUrl + 'activities/listActivities',body)
	},
	更新活动: function(body) {
		return postJson(baseUrl + 'activities/updateActivities',body)
	},
	删除活动: function(body) {
		return postJson(baseUrl + 'activities/deleteActivities?id=' + body.id)
	},
	getNews: function(body) {
		return fetch(baseUrl + 'new/list',body)
	},
	getVidedoList: function() {
		return fetch(baseUrl + 'monitor/list')
	},
	addVideo: function(body) {
		return postJson(baseUrl + 'monitor/add',body)
	},
	delVideo: function(body) {
		return postJson(baseUrl + 'monitor/delete?id=' + body.id)
	},
	getOnlineCommentator: function(body) {
		return fetch(baseUrl + 'online/get-online',body)
	},
	getLog: function(body) {
		return fetch(baseUrl + 'log/get-log-list',body)
	},
	updateLog: function(body) {
		return postJson(baseUrl + 'log/add-log',body)
	},
	chartUrlTest: function(url,body) {
		return fetch(url,body)
	},
	addChart: function(body) {
		return postJson(baseUrl + 'chart/add',body)
	},
	getNewChartData: function(url,body) {
		return fetch(url,body)
	},
	getNewChartList: function() {
		return fetch(baseUrl + 'chart/get-chart')
	},
	getCommentatorTime: function() {
		return fetch(baseUrl + 'statistics/commentator-today')
	},
	getServiceNum: function() {
		return fetch(baseUrl + 'statistics/service-num')
	},
	getLease: function() {
		return fetch(baseUrl + 'device/get-lease')
	}
}